﻿using Enring.Global;
using System;

namespace Enring.Web.Install
{
    public partial class Step2 : Installer
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnInitDatabase.Click += new EventHandler(btnInitDatabase_Click);
            btnNext.Click += new EventHandler(btnNext_Click);
        }

        void btnNext_Click(object sender, EventArgs e)
        {
            Response.Redirect("step3.aspx");
        }

        void btnInitDatabase_Click(object sender, EventArgs e)
        {
            try
            {
                Enring.EnringContext enContext = EnringContext.Current;
                if (enContext.Database.Exists())
                    enContext.Database.Delete();
                //System.Data.Entity.Database.SetInitializer<Enring.EnringContext>
                //   (new System.Data.Entity.DropCreateDatabaseIfModelChanges<Enring.EnringContext>());
                enContext.Database.CreateIfNotExists();

                labMess.Text = "成功";
                btnInitDatabase.Enabled = false;
                btnNext.Enabled = true;
            }
            catch (Exception err) {
                labMess.Text = "失败:" + err.Message ;
            }

        }
    }
}